// TickerWindow.h: interface for the CTickerWindow class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TICKERWINDOW_H__43BFD83B_27A1_41FD_9EF5_EEEDFBEA5B1D__INCLUDED_)
#define AFX_TICKERWINDOW_H__43BFD83B_27A1_41FD_9EF5_EEEDFBEA5B1D__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "resource.h"
#include "interface/TickerContentIF.h"

#define MAX_PROVIDERS 64
#define MOVETIMERID 2
#define TICKTIMERID 1

class CTickerItem;

class CTickerItem 
{
public:
	CTickerItem (INewsContentProvider* pvdr, NewsItem* news);
	virtual ~CTickerItem();
	
	CTickerItem* GetNext();
	void SetNext(CTickerItem* next);

public:
	NewsItem*		m_pNews;
	INewsContentProvider*	m_pvdr;
	// the full length of the text, including leading and trailing
	UINT			m_nTextWidth;
	UINT			m_nFirstVisiblePos;
	// Start position on screen.
	UINT			m_nScreenPos;
   HBRUSH      m_brBk;

protected:
	CTickerItem*	m_pNext; 
   void CopyNewsItem(NewsItem* dest, NewsItem* src);
};

class CTickerItemList
{
public:
	CTickerItemList ();
	virtual ~CTickerItemList();

	void AddToTail(CTickerItem* pTail);
	// If head is not NULL, RemoveHead returns 0, otherwise -1.
	int RemoveHead();
	CTickerItem* GetHead();	

protected:
	CTickerItem* m_pHead;
	CTickerItem* m_pTail;
};

class CTickerWindow : public CWindowImpl<CTickerWindow>  
{
public:
	CTickerWindow();
	virtual ~CTickerWindow();

BEGIN_MSG_MAP(CTickerWindow)
   MESSAGE_HANDLER(WM_CREATE, OnCreate)
   MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
   MESSAGE_HANDLER(WM_SIZE, OnSize)
   MESSAGE_HANDLER(WM_PAINT, OnPaint)
   MESSAGE_HANDLER(WM_TIMER, OnTimer)
   MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnDblClick)
//    COMMAND_ID_HANDLER(IDM_XXX, OnXXX)
END_MSG_MAP()

//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
   LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
   LRESULT OnDblClick(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);


	int AddProvider (INewsContentProvider* pvdr);
	void RemoveProvider (INewsContentProvider* pvdr);
	// SetMoveStep returns the old Step value, if nStepPixels == 0, only return
	//  the old step value;
	unsigned int SetMoveStep (unsigned int nStepPixels);

protected:
	UINT					m_nTickTimerID;
	UINT					m_nMoveTimerID;
	INewsContentProvider*	m_providers[MAX_PROVIDERS];
	unsigned int			m_nCurProvider;
	unsigned int			m_nMoveStep;
	CTickerItemList			m_lstItem;

protected:
	unsigned int			m_nLeading;
	unsigned int			m_nTrailing;
	unsigned int			m_nTxtHeight;

protected:
	void CallTickForAllProviders();
	void RemoveTimerMsg(UINT nTimerID);
	void MoveTicker();
	int GetNextItem(NewsItem** pItem);
	int FindNextProvider (UINT s);
	void PrepareContent (HDC hdc, UINT nScrnWidth);
	// CalcDisplayPos returns the starting screen pos for next item.
	int CalcDisplayPos (HDC hdc, int nCurScrnPos, CTickerItem* pItem);
	void DrawContent(HDC hdc);
	void DrawTickerItem(HDC hdc, CTickerItem* pItem, const LPRECT prcClient);
	bool CursorInWindow();
};

#endif // !defined(AFX_TICKERWINDOW_H__43BFD83B_27A1_41FD_9EF5_EEEDFBEA5B1D__INCLUDED_)
